package com.dogborther.controller;

import com.dogborther.LemonApplication;
import com.dogborther.view.*;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

@FXMLController
@Slf4j
public class MenuViewController implements Initializable {

    @FXML
    public Button lockVersion;
    @FXML
    public Button noLockVersion1;
    @FXML
    public Button noLockVersion2;
    @FXML
    public Button noLockVersion3;
    @FXML
    public VBox mainBox;
    @FXML
    public BorderPane menuViewRootPane;
    @Autowired
    private MenuView menuView;
    /*    @Autowired
        private Mode0LockView mode0LockView;
        @Autowired
        private Mode1UnLockView mode1UnLockView;
        @Autowired
        private Mode2UnLockView mode2UnLockView;
        @Autowired
        private Mode3UnLockView mode3UnLockView;*/
    Scene scene;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        Stage stage = new Stage();
        URL resource = MainViewController.class.getResource("/css/common.css");
        String css = resource.toExternalForm();
        lockVersion.setOnAction(e -> {
            MainViewController.setSelectMode(0);
            try {
                Pane load = FXMLLoader.load(MenuViewController.class.getResource("/view/mode0LockView.fxml"));
                load.getStylesheets().add(css);
                scene=new Scene(load);
                stage.setScene(scene);
                stage.setTitle("可能会死锁的");
                stage.getIcons().add(new Image("/image/icon.jpg"));
                stage.show();

            } catch (IOException ex) {
                System.out.println("::");
            }
        });
        noLockVersion1.setOnAction(e -> {
            MainViewController.setSelectMode(1);
            try {
                Pane load = FXMLLoader.load(MenuViewController.class.getResource("/view/mode1UnLockView.fxml"));
                load.getStylesheets().add(css);
                scene=new Scene(load);
                stage.setScene(scene);
                stage.setTitle("奇偶交替不死锁");
                stage.getIcons().add(new Image("/image/icon.jpg"));
                stage.show();
            } catch (IOException ex) {
                System.out.println("::");
            }
        });
        noLockVersion2.setOnAction(e -> {
            MainViewController.setSelectMode(2);
            try {
                Pane load = FXMLLoader.load(MenuViewController.class.getResource("/view/mode2UnLockView.fxml"));
                load.getStylesheets().add(css);
                scene=new Scene(load);
                stage.setScene(scene);
                stage.setTitle("最后一人先右后左");
                stage.getIcons().add(new Image("/image/icon.jpg"));
                stage.show();
            } catch (IOException ex) {
                System.out.println("::");
            }
        });
        noLockVersion3.setOnAction(e->{
            MainViewController.setSelectMode(3);
            try {
                Pane load = FXMLLoader.load(MenuViewController.class.getResource("/view/mode3UnLockView.fxml"));
                load.getStylesheets().add(css);
                scene=new Scene(load);
                stage.setScene(scene);
                stage.setTitle("最多同时4个人进餐版本");
                stage.getIcons().add(new Image("/image/icon.jpg"));
                stage.show();
            } catch (IOException ex) {
                System.out.println("::");
                ex.printStackTrace();
            }
        });
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                MainViewController.setIsPlay(false);
            }
        });
    }

}
